module PortfolioHelper
  MAX_DELTA_PERCENT = 2  
  
  #create stock price update data for a given stock
  def create_stock_text(stock)
    old_price = price(stock)
    new_price = update_price(stock)
    
    offer_price = new_price * 1.001
    movement = (new_price > old_price) ? "up" : "down"
    
    msg = [stock, new_price, movement]
    
    return msg
  end
  
  def price(stock)
    $prices[stock] = (rand() * 100) if $prices[stock].nil?
    $prices[stock]
  end
  
  def update_price(stock)
    price_change = (2 * rand() * MAX_DELTA_PERCENT) - MAX_DELTA_PERCENT
    $prices[stock] = price(stock) * (100 + price_change ) / 100
  end    
end
